package org.boulderfoodrescue.webapp.client.dialogs.confirm;

import org.boulderfoodrescue.webapp.client.dialogs.DialogCallback;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class ConfirmDialogView extends Composite implements HasText {

  private static ConfirmDialogViewUiBinder uiBinder = GWT
      .create(ConfirmDialogViewUiBinder.class);

  interface ConfirmDialogViewUiBinder extends
      UiBinder<Widget, ConfirmDialogView> {
  }

  public ConfirmDialogView(DialogCallback confirmDialog) {
    initWidget(uiBinder.createAndBindUi(this));
    this.confirmDialog = confirmDialog;
  }

  @UiField
  Button okButton;
  @UiField
  Button cancelButton;
  @UiField
  Label confirmationText;
  
  private DialogCallback confirmDialog;
  
  @UiHandler("okButton")
  public void onOkButtonClick(ClickEvent event)
  {
    confirmDialog.onConfirmOperation();
  }
  
  @UiHandler("cancelButton")
  public void onCancelButtonClick(ClickEvent event)
  {
    confirmDialog.onCancelOperation();
  }
  
  @Override
  public String getText() {
    return confirmationText.getText();
  }
  @Override
  public void setText(String text) {
    confirmationText.setText(text);
  }
}
